<template>
    <l-dialog :visible.sync="formVisible" :height="400" :width="600" @close="handleCloseForm" @opened="handleOpenedForm"
        :hasBtns="true" :showMinBtn="false" :showFullscreenBtn="false">
        <template #title class="header">
            <h3>评定</h3>
        </template>
        <template>
            <el-form :model="awaitAssessDialogFormData" :disabled="disabled" :rules="rules" size="mini"
                labelPosition="right" labelWidth="140px" ref="form">
                <el-row :gutter="20" style="margin-right:0px">
                    <div class="l-rblock">
                        <el-col :span="24">
                            <el-form-item label="是否符合兑现条件" prop="isRequirement">
                                <!-- <l-select :options="[{ label: '是', value: true }, { label: '否', value: false }]"
                                    v-model="awaitAssessDialogFormData['isRequirement']" placeholder="请选择" /> -->
                                <el-radio :label="true" v-model="awaitAssessDialogFormData['isRequirement']">是</el-radio>
                                <el-radio :label="false" v-model="awaitAssessDialogFormData['isRequirement']">否</el-radio>
                            </el-form-item>
                            <el-form-item label="评定日期" prop="evaluationDate">
                                <el-date-picker v-model="awaitAssessDialogFormData['evaluationDate']" type="date"
                                    value-format="yyyy-MM-dd" placeholder="选择日期">
                                </el-date-picker>
                            </el-form-item>
                            <el-form-item label="综合评价" prop="comprehensiveEvaluationCode">
                                <l-select :options="evaluationlevelOptions"
                                    v-model="awaitAssessDialogFormData['comprehensiveEvaluationCode']" placeholder="请选择" />
                            </el-form-item>
                            <el-form-item label="说明" prop="explain">
                                <el-input type="textarea" :rows="2" placeholder="请输入内容"
                                    v-model="awaitAssessDialogFormData['explain']">
                                </el-input>
                            </el-form-item>
                        </el-col>
                    </div>
                </el-row>
            </el-form>
        </template>
        <template #btns>
            <el-button size="small" @click="handleCancel">取消</el-button>
            <el-button size="small" type="primary" @click="handleCommit">提交</el-button>
        </template>
    </l-dialog>
</template>
  
<script>
import { awaitAssessDialogFormData, assessdialogapi } from "./columns";
export default {
    components: {
    },
    props: {
        formEdit: {
            type: Boolean,
            default: true
        },
        disabled: {
            type: Boolean,
            dafault: false
        },
    },
    data() {
        return {
            formVisible: false,
            awaitAssessDialogFormData,
            rules: {
                isRequirement: [{ required: true, message: "请输入内容", trigger: "change" }],
                evaluationDate: [{ required: true, message: "请输入内容", trigger: "change" }],
                comprehensiveEvaluationCode: [{ required: true, message: "请输入内容", trigger: "change" }],
            },
        };
    },
    computed: {
        evaluationlevelOptions() {
            return this.lr_dataItemOptions(this.lr_dataItem['evaluationlevel']);
        },
    },
    mounted() {
        this.lr_loadDataItem("evaluationlevel");
    },
    methods: {
        open(row = {}, options = {}) {
            this.awaitAssessDialogFormData = Object.assign({}, { landId: row.id }, awaitAssessDialogFormData);
            this.formVisible = true;
            this.$nextTick(() => {
                this.$refs.form.clearValidate();
            })
        },
        handleCancel() {
            this.formVisible = false;
        },
        handleCommit() {
            this.$refs.form.validate(async validate => {
                if (validate) {
                    const { landId, isRequirement, evaluationDate, comprehensiveEvaluationCode, explain } = this.awaitAssessDialogFormData;
                    let requestBody = {
                        landId,
                        isRequirement,
                        evaluationDate,
                        comprehensiveEvaluationCode,
                        explain
                    }
                    let res = await assessdialogapi.add(requestBody);
                    if (res.data.code === 200) {
                        this.$message({
                            type: "success",
                            message: "新增评定成功"
                        })
                        // 重新刷新页面
                        this.$emit("refresh");
                        this.$store.commit("count/changeCount")
                        this.formVisible = false;

                    } else {
                        this.$message({
                            type: "error",
                            message: "新增评定失败"
                        })
                    }
                } else {
                    this.$message({
                        type: "error",
                        message: "您有必选项未填写"
                    })
                }
            })
        },
        handleCloseForm() {
            this.formVisible = false
        },
        async handleOpenedForm(showLoading, hideLoading) {
            if (this.formEdit) {
                showLoading('加载数据中...')
                hideLoading()
            }
        },
    }
};
</script>
<style lang="scss" scoped>
.header {
    width: 100%;
}

::v-deep .el-dialog__body {
    padding: 10px;
}

.dialog-container {
    overflow: auto;
}
</style>